package cn.afactory.tygz.ui.base.views;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import java.util.ArrayList;
import java.util.List;

import cn.afactory.tygz.R;
import cn.afactory.tygz.ui.base.adapter.CommunityGridAdapter;
import cn.afactory.tygz.ui.base.adapter.NearByPeoplesAdapter;
import cn.afactory.tygz.ui.base.entity.CommunityInfo;

/**
 * Created by Kenneth on 15/9/14.
 */
public class CommunityGridView extends LinearLayout {

    private static final int SPAN_COUNT = 3;

    private List<CommunityInfo> mCommunityInfoList = new ArrayList<CommunityInfo>();

    private RecyclerView mRecyclerView;
    private CommunityGridAdapter mAdapter;

    private CommunityGridView(Context context, List communityInfoList) {
        super(context);
    }

    public CommunityGridView(Context context, AttributeSet attrs, List communityInfoList) {
        super(context, attrs);
        mCommunityInfoList = communityInfoList;
        initView(context, attrs);
    }

    public CommunityGridView(Context context, AttributeSet attrs, int defStyle, List communityInfoList) {
        super(context, attrs, defStyle);
        mCommunityInfoList = communityInfoList;
        initView(context, attrs);
    }

    private void initView(Context context, AttributeSet attrs){

        View rootView = LayoutInflater.from(context).inflate(R.layout.fg_community_grid, this, true);
        mRecyclerView = (RecyclerView)rootView.findViewById(R.id.fg_community_list);
        mRecyclerView.setLayoutManager(new GridLayoutManager(context, SPAN_COUNT));
        mAdapter = new CommunityGridAdapter(context, mCommunityInfoList);
        mRecyclerView.setAdapter(mAdapter);
    }
}
